<template>
  <view class="container">
    <view class="main">
      <!--
      <view
        v-if="addressList.length===0"
        class="empty">
        <view class="img">
          <image src="http://jiales.gz-yami.com/addr.png" />
        </view>
        <view class="txt">
          您还没有生成盘点报告
        </view>
        </view>
        -->
      <uni-calendar
        :insert="true"
        :lunar="true"
        @change="checkDate"
        date
      ></uni-calendar>
            <uni-section title="请选择养殖地址" type="line">
        <uni-data-select
          v-model="value"
          :localdata="addressList"
          @change="changeAddress"
        ></uni-data-select>
      </uni-section>
    </view>
    <view>

    </view>
    <view class="footer" @click="exportPanDian">
      <text>新增盘点报告</text>
    </view>
    <view>
      <uni-popup ref="messagepopup" type="message">
        <uni-popup-message
          :type="exportData.msgType"
          :message="exportData.messageText"
          :duration="2000"
        ></uni-popup-message>
      </uni-popup>
    </view>
  </view>
</template>

<script setup>
import moment from "moment/moment";
const messagepopup = ref(null);
const exportData = reactive({
  msgType: "",
  messageText: "",
  pandianTime: moment(new Date()).format("yyyy-MM-DD"),
});
const checkDate = (e) => {
  exportData.pandianTime = e.fulldate;
};
const selectedAddress = reactive({
  value: null,
});
const changeAddress = (e) => {

  selectedAddress.value = e;
}
/**
 * 新增盘点报告
 */
const exportPanDian = () => {
  let param = {
    userId: selectedAddress.value,
    pandianTime: exportData.pandianTime,
  };
  http
    .request({
      url: "/fyjy/api/generatePandianReport",
      method: "POST",
      data: param,
    })
    .then(({ data, code }) => {
      if (code === 200) {
        exportData.msgType = "success";
        exportData.messageText = "操作成功!";
        messagepopup.value.open();
      } else {
        exportData.msgType = "error";
        exportData.messageText = "操作失败!";
        messagepopup.value.open();
      }
    });
};
const order = ref(-1);
onLoad((option) => {
  if (option.order) {
    order.value = option.order;
  }
});

const addressList = ref([]);

/**
 * 加载养殖地址列表
 */
onShow(() => {
  onGetList()
});

/**
 * 获取收获列表接口
 */
const onGetList = () => {
  uni.showLoading();
  http
    .request({
      url: "/app/api/getAddressById",
      method: "GET",
    })
    .then(({ data }) => {
      addressList.value = data;
      uni.hideLoading();
    });
};



</script>

<style scoped lang="scss">
@use "./vaccineImplementReport.scss";
</style>
